#include <stdio.h>
#include <fcntl.h>
#include <termios.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
int main()
{
  int fd;
  fd = open("/dev/ttyUSB0",O_RDWR | O_NOCTTY | O_NDELAY);

  if(fd == 1)
     printf("\n  Error! in Opening ttyUSB0\n");
  else
     printf("\n  ttyUSB0 Opened Successfully\n");


  struct termios PortSet;

  tcgetattr(fd, &PortSet);

  cfsetispeed(&PortSet,B115200);
  cfsetospeed(&PortSet,B115200);

  PortSet.c_cflag |= CREAD | CLOCAL;
  PortSet.c_cflag &= ~PARENB;  //DISABLES THE PARITY
  PortSet.c_cflag &= ~CSTOPB;  //1 BIT
  PortSet.c_cflag &= ~CSIZE;  //CLEAR SIZE
  PortSet.c_cflag |=  CS8;  //8 BIT DATAS
  PortSet.c_iflag &= ~(IXON | IXOFF | IXANY);
  PortSet.c_iflag &= ~(ICANON | ECHO | ECHOE | ISIG);
  PortSet.c_oflag &= -OPOST;

  if((tcsetattr(fd,TCSANOW,&PortSet)) != 0) 
    { 
      perror("\n  com set error"); 
      return -1; 
    } 
  else
    printf("set done!\n"); 
  int ret=0;
  int buffer_in, ch[1];
while(1)
{
  buffer_in = getchar();
  ch[0] = buffer_in;
  ret = write(fd,ch,1);
}
  close(fd);
  return 0;
}
